<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>

<script type="text/javascript">
	var facilitatorgrid;
	$(function() {

		facilitatorgrid = $('#facilitatorgrid')
				.datagrid(
						{
							//title : '列表',
							url : '${ctx}/autoinn/facilitator/list',
							striped : true,
							rownumbers : true,
							pagination : true,
							singleSelect : true,
							idField : 'id',
							sortName : 'innertime',
							sortOrder : 'desc',
							pageSize : 50,
							pageList : [ 10, 20, 30, 40, 50, 100, 200, 300,
									400, 500 ],
							frozenColumns : [ [ {
								width : '120',
								title : '姓名',
								field : 'name'
							
							} ] ],
							columns : [ [
									{
										width : '80',
										title : '管理类别',
										field : 'type',
										formatter : function(value, row) {
											if (value==0) {
												return sy.formatString("<span align='center'>管理员</span>");
											} else {
												return sy.formatString("<span align='center'>子级管理员</span>");
											}
										}
									},
									{
										width : '100',
										title : '所属门店',
										field : 'storename'
									},
									
								
									{
										width : '60',
										title : '状态',
										field : 'state',
										formatter : function(value, row) {
											if (value==0) {
												return sy.formatString("<span align='center'>未启用</span>");
											} else {
												return sy.formatString("<span align='center'>启用</span>");
											}
										}
									},
									{
										width : '130',
										title : '添加时间',
										field : 'innertime'
									},
									{
										width : '150',
										title : '操作',
										field : 'action',
										formatter : function(value, row) {
											var str = "";
											
											<shiro:hasPermission name="/autoinn/facilitator/del">
											str += sy
													.formatString(
															'<span onclick="facilitatorremoveFun(\'{0}\');" style="margin-left:3px;cursor:pointer;">【{1}】</span>',
															row.id, "删除");
                                            </shiro:hasPermission>
                                            <shiro:hasPermission name="/autoinn/facilitator/update/pro/ser">
											str += sy
													.formatString(
															'<span onclick="facilitatorupdateFun(\'{0}\',\'{2}\');" style="margin-left:3px;cursor:pointer;">【{1}】</span>',
															row.storeid, "修改",row.id);
											</shiro:hasPermission>
											return str;
										}
									} ] ],
							toolbar : '#facilitatortoolbar',
							onBeforeLoad : function(param) {
								parent.$.messager.progress({
									text : '数据加载中....'
								});
							},
							onLoadSuccess : function(data) {
								
								parent.$.messager.progress('close');
								$('#facilitatorstorelist').combotree({
									url : '${ctx}/autoinn/store/sellist',
									idFiled : 'id',
									textFiled : 'name'
									
								});
							}

						});
	});

	//删除
	var facilitatorremoveFun = function(id) {
		parent.$.messager.confirm('询问', '您确定要删除此记录？', function(r) {
			if (r) {
				$.post('${ctx}/autoinn/facilitator/del?id=' + id, {
					id : id
				}, function() {
					facilitatorgrid.datagrid('reload');
				}, 'json');
			}
		});
	};

	
	//修改
	var facilitatorupdateFun = function(id,fid) {
		$('<div/>').dialog({
			href : '${ctx}/autoinn/facilitator/update/pro?storid=' + id +'&fid='+fid,
			width : 540,
			height : 200,
			modal : true,
			title : '修改信息',
			buttons : [ {
				text : '修改',
				iconCls : 'icon-add',
				handler : function() {
					var d = $(this).closest('.window-body');

					$('#facilitator_updateForms').form('submit', {
						url : '${ctx}/autoinn/facilitator/update/pro/json',
						success : function(result) {
							try {
								var r = $.parseJSON(result);

								if (r.success) {
									
									facilitatorgrid.datagrid('reload'); // 刷新数据  
									d.dialog('destroy');
								}

								$.messager.show({
									title : '温馨提示',
									msg : r.message
								});

							} catch (e) {
								$.messager.alert('温馨提示', e.message);
								return;
							}

						}

					});

				}

			} ],
			onLoad : function() {
				//$("#res_updateForm").form('load',entity);

			},
			onClose : function() {
				$(this).dialog('destroy');
			}
		});

	};
</script>
<!-- 界面布局  -->
<div class="easyui-layout" style="width: 100%; height: 100%;"
	data-options="fit:true,border:false">

	<div id="facilitatortoolbar" style="display: none;">

		<table>
			<tr>
				<td>
					<form id="facilitatorsearchForm">
						<table>
							<tr style="font-size: 13px;">
								<td>电话号码</td>
								<td><input name="phone" style="width: 80px;" /></td>
								<td>门店</td>
								<td><input id="facilitatorstorelist" name="storeid"
					class="easyui-combotree" style="width: 155px;" /></td>
							
							  <td>
							  创建时间：
							  </td>	
							  <td>
							  <input name="startime" class="Wdate"
									onclick="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})"
									readonly="readonly" style="width: 160px;" />-<input
									name="endtime" class="Wdate"
									onclick="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})"
									readonly="readonly" style="width: 160px;" /></input>
							  </td>

								<td><a href="javascript:void(0);" class="easyui-linkbutton"
									data-options="iconCls:'icon-search',plain:true"
									onclick="facilitatorgrid.datagrid('load',sy.serializeObject($('#facilitatorsearchForm')));">过滤</a>
									
									<a
									href="javascript:void(0);" class="easyui-linkbutton"
									data-options="iconCls:'icon-reload',plain:true"
									onclick="$('#facilitatorsearchForm input').val('');facilitatorgrid.datagrid('load',{});">重置过滤</a></td>
							</tr>
						</table>
					</form>
				</td>
			</tr>
		
		</table>
	</div>
	<div data-options="region:'center',title:'服务商管理'" style="padding: 2px;">
		<div class="easyui-layout" data-options="fit : true,border : false">
			<div data-options="region:'center',border:false">
				<table id="facilitatorgrid" data-options="fit:true,border:false"></table>
			</div>
		</div>
	</div>
	<!-- 	<div data-options="region:'east', split:true" style="width: 320px;">
		<div class="easyui-panel"
			data-options="fit:true,border:false,title:'权限设置'"
			style="padding: 10px;" id="user-panel"></div>
	</div> -->
</div>